package com.util;

import com.entity.Member;
import com.exception.CustomerException;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;

public class BeanUtil {

    public static Member createBean(HttpServletRequest request){
        try {


            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
            Member member = new Member();
            member.setName(request.getParameter("name"));
            member.setSex(request.getParameter("sex"));
            member.setPhone(request.getParameter("phone"));
            member.setCpoint(Integer.parseInt(request.getParameter("cpoint")));
            member.setJointime(simpleDateFormat.parse(request.getParameter("jointime")));
            if (!request.getParameter("num").equals("")){
                member.setNum(Integer.parseInt(request.getParameter("num")));              //更新的时候需要num，添加的时候不需要num
            }
            member.setBirthday(simpleDateFormat.parse(request.getParameter("birthday")));
            return member;
        }catch (Exception e){
            e.printStackTrace();
            throw new CustomerException("日期转换失败！");
        }
    }
}
